<template>
  <div class="body">
    <div class="header" v-show="!isShow">
      <div class="header-shop">
        <div class="header-left">
          <span>购物车</span>
        </div>
        <div class="header-right">
          <i class="iconfont icon-youhuiquan"></i>
          <span>编辑</span>
        </div>
      </div>
      <div class="shopcart-emty">
        <ul>
          <li>
            <van-icon name="setting-o" />30天无忧退货
          </li>
          <li>
            <van-icon name="setting-o" />48小时快速退款
          </li>
          <li>
            <van-icon name="setting-o" />满99元免邮费
          </li>
        </ul>
        <div class="shopcar">
          <img src="./static/image/shop.png" alt="">
        </div>
        <div class="addshopcart">去添加点什么吧</div>
      </div>
    </div>
    <div class="isShow" v-show="isShow">
      <div class="header">
        <div class="header-shop">
          <div class="header-left">
            <span>购物车</span>
          </div>
          <div class="header-right">
            <i class="iconfont icon-youhuiquan"></i>
            <span>编辑</span>
          </div>
        </div>

        <div class="title">自营仓商品,已满99元免邮</div>
        <div class="product">
          <div class="product-shop">全场换购</div>
          <span>已满足49元超值换购</span>
          <a href="javascript:;">再逛逛</a>

        </div>
        <van-notice-bar color="#1989fa" background="#ecf9ff" mode="link">
          去换购商品
        </van-notice-bar>
      </div>
      <div class="main">
        <div class="main-title">
          <div class="main-header">特价抢购中</div>
          <span class="main-time">距优惠结束 5天16小时</span>
        </div>
        <div class="box1" v-for="item in getcartList" :key="item.id">
          <div class="box-radio-wrap">
            <i class="iconfont icon-gouxuan choose" v-if="item.isChecked" @click="handlecheck(item)"></i>
            <i class="iconfont icon-weigouxuan choose" v-else @click="handlecheck(item)"></i>
          </div>
          <van-swipe-cell>
            <van-card :price="item.skuPrice" :title="item.skuName" class="goods-card" :thumb="item.imgUrl" />
            <div class="guige">
              <a href="">180x210cm:烟粉</a>
              <a href="" class="iconfont icon-xialajiantou"></a>
            </div>
            <div class="foot">
              <span class="yuanjia">222</span>
              <div class="num">
                <div class="num_der_wrap">
                  <a href="" class="der">+</a>
                </div>
                <input type="text" value="1">
                <div class="num_der_wrap">
                  <a href="" class="der">-</a>
                </div>
              </div>
            </div>
            <div class="bottom">
              <i class="iconfont icon-cangchucangku ziying"></i>
              <span>自营仓商品满99免邮</span>
            </div>
            <template #right>
              <van-button square text="删除" type="danger" class="delete-button" />
            </template>
          </van-swipe-cell>

        </div>
      </div>
      <div class="last">
        <div class="last-submit">
          <i class="iconfont icon-gouxuan choose" @click="isCheckedAll" v-if="isCheckedAll"></i>
          <i class="iconfont icon-weigouxuan choose" v-else @click="choosed"></i>
          <div class="last-right">
            <div class="priceAll">合计 ￥215</div>
            <div class="price">已优惠 ￥215</div>
          </div>
          <button class="goshop">下单</button>
        </div>

      </div>

    </div>
  </div>
</template>

<script>
import { shopList, reqCheckSkuInCart } from "@/api";
export default {
  name: "",
  data() {
    return {
      goodsId: [100, 200, 300, 4000],
      radio: "1",
      isShow: true,
      cartInfoList: [],
    };
  },
  mounted() {
    this.getShopList();
  },
  methods: {
    //单选是否勾选
    async handlecheck(item) {
      //获取当前操作商品的skuId，isChecked
      let { skuId, isChecked } = item;
      //维护一个新的值
      isChecked = isChecked ? 0 : 1;
      let result = await reqCheckSkuInCart(skuId, isChecked);
      console.log(result);
      //如果勾选不成功
      if (result.code !== 200) {
        result.message("请求失败");
      }
      //重新刷新数据
      this.getShopList();
    },
    //获取购物车列表数据
    async getShopList() {
      let result = await shopList();
      console.log(result);
      if (result.code == 200) {
        this.cartInfoList = result.data;
      }
    },
    choosed(){}
  },
  computed: {
    //全选、全不选
    isCheckedAll(){
    return this.getcartList.every(item=>item.isChecked===1)
    },
    getcartList() {
      let cart = [];
      if (this.cartInfoList.length) {
        this.cartInfoList.forEach((item) => {
          cart = cart.concat(item.cartInfoList);
        });
      }
      console.log(cart);
      return cart;
    },
  },
};
</script>
<style lang="less" scoped>
@import url("./static/iconfont/iconfont.css");
.goods-card {
  // margin-left: 30px;
  background-color: white;
  .van-card__header {
    .van-card__content {
      .van-card__title {
        font-size: 16px;
        font-weight: 500;
      }
    }
  }
}

.delete-button {
  height: 100%;
}
</style>
<style lang="less" scoped>
.body {
  height: 100vh;
  background: rgb(244, 244, 244);
  .isShow {
    .last {
      background: white;
      width: 100%;
      position: fixed;
      bottom: 50px;
      left: 0;

      .last-submit {
        display: flex;
        justify-content: space-between;
        // align-items: center;
        .van-radio-group {
          .van-radio {
            .van-radio__icon {
              .van-icon {
                margin-left: 12px;
                margin-right: 10px;
              }
            }
          }
          margin-top: 10px;
        }
        .goshop {
          width: 130px;
          padding-bottom: 20px;
          height: 90px;
          background: rgb(221, 26, 33);
          margin-right: 0;
          border: none;
          font-size: 16px;
          color: white;
          display: inline-block;
          text-align: center;
        }
        .choose {
          font-size: 24px;
          margin-right: 60px;
          margin-top: 15px;
          margin-left: 12px;
          display: block;
          color: red;
        }
        .last-right {
          margin-top: 10px;
          .priceAll {
            color: red;
            font-size: 18px;
          }
          .price {
            font-size: 12px;
            margin-left: 12px;
          }
        }
      }
    }
  }
  .header {
    background: white;

    .shopcart-emty {
      background: rgb(238, 238, 238);
      height: 60px;
      .shopcar {
        position: relative;

        img {
          position: absolute;
          left: 50%;
          margin-left: -60px;
          top: 50%;
          width: 130px;
          height: 130px;
          margin-top: 150px;
        }
      }
      .addshopcart {
        position: absolute;
        font-size: 20px;
        text-align: center;
        color: #ccc;
        margin-top: 280px;
        margin-left: 33%;
      }
      ul {
        li {
          .van-icon {
            font-size: 5px;
            margin-right: 5px;
          }
        }
      }
      .van-icon {
        font-size: 14px;
      }
      ul {
        display: flex;
        line-height: 60px;
        justify-content: space-around;
        font-size: 14px;
      }
    }
    .header-shop {
      padding: 10px;
      display: flex;
      justify-content: space-between;

      box-shadow: 0 1px 1px rgb(245, 243, 243);
      .header-left {
        line-height: 30px;
        span {
          font-size: 18px;
        }
      }
      .header-right {
        font-size: 16px;
        line-height: 30px;

        i {
          color: rgb(252, 117, 123);
          display: block;
          margin-right: 10px;
          float: left;
          font-size: 30px;
        }
      }
    }

    .title {
      height: 30px;
      background: rgb(255, 248, 216);
      color: rgb(244, 143, 24);
      font-size: 14px;
      padding-left: 15px;
      line-height: 30px;
    }
    .product {
      padding: 10px 10px;
      display: flex;
      justify-content: space-between;
      .product-shop {
        line-height: 10px;
        color: white;
        background: rgb(250, 130, 95);
        font-size: 12px;
        padding: 5px;
      }
      span {
        margin-right: 70px;
        color: rgb(51, 51, 51);
        font-size: 15px;
      }
      a {
        font-size: 12px;
        color: rgb(221, 26, 33);
      }
    }
  }
  .main {
    margin-top: 10px;

    .box1 {
      background: white;
      display: flex;
      // align-items: center
      padding-left: 16px;
      position: relative;
      margin-top: 10px;
      //  .van-swipe-cell__wrapper{
      //    margin-top: 10px;
      //  }
      .box-radio-wrap {
        padding-top: 30px;
        .choose {
          font-size: 24px;
          color: red;
        }
        .isChecked-dan {
          width: 30px;
          height: 20px;
        }
      }

      .goods-card {
        display: block;
        .van-card__header {
          .van-card__content {
            .van-card__title {
              width: 200px;
            }
          }
        }
      }
      //  .gouxuan{
      //    position: absolute;
      //   font-size: 25px;
      //  top: 35px;
      //  left: 6px;
      //  border-radius: 50%;
      //  width: 30px;
      //  height: 30px;
      //  }
      &.van-radio__icon {
        top: 35px;
        position: absolute;
        left: 6px;
      }

      .guige {
        border: 1px solid #ccc;
        position: absolute;
        top: 45px;
        font-size: 14px;
        left: 115px;
      }
      .foot {
        position: absolute;
        top: 80px;
        right: 20px;

        .yuanjia {
          text-decoration: line-through;
          float: left;
          margin-right: 30px;
          font-size: 16px;
          color: #ccc;
          margin-top: -5px;
        }
        .num {
          display: flex;
          border: 1px solid #ccc;
          // float: right;
          width: 100px;
          height: 30px;
          text-align: center;
          line-height: 20px;
          .num_der_wrap {
            display: flex;
            align-items: center;
            justify-content: center;
            flex: 1;
          }
          &:nth-child(1) {
            margin-left: 10px;
          }
          .der {
            color: #ccc;
            text-align: center;
          }
          input {
            // flex: 0.5;
            width: 40px;

            outline: none;
            border: none;
            border-left: 1px solid #ccc;
            border-right: 1px solid #ccc;
            text-align: center;
          }
        }
      }
      .bottom {
        // margin: 10px 0 10px 10px;
        margin-top: 10px;
        .ziying {
          font-size: 14px;
          margin-right: 5px;
          color: blue;
        }
        span {
          font-size: 14px;
        }
      }
    }
    .main-title {
      margin-left: 50px;
      display: flex;
      .main-header {
        width: 70px;
        height: 18px;
        border: 1px solid orange;
        font-size: 12px;
        line-height: 18px;
        text-align: center;
        margin-right: 10px;
        color: orange;
      }
      .main-time {
        font-size: 6px;
        padding-top: 5px;
      }
    }
  }
}
</style>